package org.ncibi.cytoscape.metscape.network;

import org.ncibi.cytoscape.metscape.data.Attributes;
import org.ncibi.metab.network.edge.MetabolicEdge;
import org.ncibi.metab.network.node.MetabolicNode;

import cytoscape.CyEdge;
import cytoscape.CyNode;
import cytoscape.Cytoscape;
import cytoscape.data.Semantics;

public abstract class AbstractEdgeTranslator implements EdgeTranslator
{
    protected abstract void addEdgeAttributes(String id, MetabolicEdge edge);
    protected abstract String getInteraction(MetabolicEdge edge);

    @Override
    public CyEdge toCyEdge(MetabolicEdge edge)
    {
        MetabolicNode sourceNode = edge.getSource();
        CyNode source = Cytoscape.getCyNode(sourceNode.getId(), true);

        MetabolicNode targetNode = edge.getTarget();
        CyNode target = Cytoscape.getCyNode(targetNode.getId(), true);

        CyEdge cyEdge = Cytoscape.getCyEdge(source, target, Semantics.INTERACTION,
        		getInteraction(edge), true, edge.isDirected());
        addCommonAttributes(cyEdge.getIdentifier(), edge);
        addEdgeAttributes(cyEdge.getIdentifier(), edge);
        return cyEdge;
    }
    
    private void addCommonAttributes(String id, MetabolicEdge edge) {
    	Attributes.edge.setAttribute(id, "Type",
    			edge.getType().toDisplayName());
    	Attributes.edge.setAttribute(id, "direction",
    			edge.getDirection().toDirectionAttribute());
	}
}
